"""
存放的是后台页面的登录与相关元素的定位
"""
from common.Base import open_browser, Base

login_url = "http://localhost:8080/ecshop/admin/"


class Back_login_page(Base):
    X_loc = ("css selector", "[onclick='btnCancel(this)']")
    log_loc = ("id", "cloudLogin")
    name_loc = ("name", "username")
    password_loc = ("name", "password")
    login_loc = ("class name", "btn-a")

    def click_X(self):
        '''
        点击后台页面的X
        :return:
        '''
        self.click(self.X_loc)

    def click_cloud_log(self):
        '''
        点击进入后台登录
        :return:
        '''
        self.click(self.log_loc)

    def input_name(self, username):
        '''
        定位用户名并输入
        :param username: 用户名
        :return:
        '''
        self.send_text(self.name_loc, username)

    def input_password(self, password):
        '''
        定位密码并输入
        :param password: 密码
        :return:
        '''
        self.send_text(self.password_loc, password)

    def click_login(self):
        '''
        点击登录
        :return:
        '''
        self.click(self.login_loc)


if __name__ == '__main__':
    # 打开浏览器
    driver = open_browser()
    lg = Back_login_page(driver)
    # 打开网页
    lg.open_url(login_url)
    lg.click_X()
    lg.click_cloud_log()
    lg.input_name("jiao")
    lg.input_password("admin123")
    lg.click_login()